package com.zbkj.admin.controller.publicly;

import com.github.pagehelper.PageInfo;
import com.zbkj.common.model.monitor.ZfbMonitorEquipment;
import com.zbkj.common.model.system.SystemAttachment;
import com.zbkj.common.monitorchannel.GetDeviceModelV3Request;
import com.zbkj.common.monitorchannel.GetMultiMediaAddrV3Request;
import com.zbkj.common.monitorchannel.vo.*;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.ProductSearchRequest;
import com.zbkj.common.request.monitor.ZfbMonitorEquipmentCondition;
import com.zbkj.common.request.monitor.ZfbMonitorEquipmentRequest;
import com.zbkj.common.request.monitor.ZfbMonitorEquipmentSearchReq;
import com.zbkj.common.response.ZfbMonitorEquipmentAvailableResponse;
import com.zbkj.common.response.ZfbMonitorEquipmentStatusResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.SystemAttachmentService;
import com.zbkj.service.service.monitor.IZfbMonitorEquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: MonitorController
 * @Description: TODO
 * @Author: fanbing
 * @Date: 2024/6/30 13:13
 * @Version: V1.0
 **/
@Slf4j
@RestController
@RequestMapping("api/publicly/brand/monitor/quipment")
@Api(tags = "监控设备-控制器")
public class PubliclyMonitorQuipmentController {

    @Autowired
    private IZfbMonitorEquipmentService zfbMonitorEquipmentService;
    @Autowired
    private SystemAttachmentService systemAttachmentService;


    @ApiOperation(value = "查询设备列表(展厅使用)")
    @GetMapping(value = "/getMerchantPageList")
    public CommonResult<CommonPage<ZfbMonitorEquipment>> getMerchantPageList(@Validated ZfbMonitorEquipmentRequest searchRequest) {
        try {
            PageInfo<ZfbMonitorEquipment> pageInfo = zfbMonitorEquipmentService.getAdminPagePublicly(searchRequest);
            return CommonResult.success(CommonPage.restPage(pageInfo));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    @ApiOperation(value = "唤醒设备(展厅使用)")
    @GetMapping(value = "/wakeUpEquipment/{license}")
    public CommonResult wakeUpEquipment(@PathVariable String [] license) {
        log.info("#wakeUpEquipment#license=[{}]", license);
        return CommonResult.success(zfbMonitorEquipmentService.wakeUpEquipment(license));
    }

    @ApiOperation(value = "最新监控截图(展厅使用)") //配合swagger使用
    @RequestMapping(value = "/images/list", method = RequestMethod.GET)
    public CommonResult<List<SystemAttachment>> getList(@Validated PageParamRequest pageParamRequest) {
        return CommonResult.success(systemAttachmentService.getLatestList(pageParamRequest));
    }

    @ApiOperation(value = "查询可用设备列表(展厅使用)",notes = "直接返回可用的设备，如果传入的设备部分不可用，有可能是之前播放过的设备")
    @GetMapping(value = "/list/available/{license}")
    public CommonResult<ZfbMonitorEquipmentAvailableResponse> getAvailableList(@PathVariable String [] license, @RequestParam(value = "num", required = false) Integer num) {
        return CommonResult.success(zfbMonitorEquipmentService.getAvailableList(license, num));
    }

    @ApiOperation(value = "查询设备状态(展厅使用)")
    @GetMapping(value = "/status/{license}")
    public CommonResult<List<ZfbMonitorEquipmentStatusResponse>> getStatus(@PathVariable String [] license) {
        return CommonResult.success(zfbMonitorEquipmentService.getStatus(license));
    }
}
